/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       text_window.h

	$Header: /game/text_window.h $

	$NoKeywords: $

 ************************************************************************/
#ifndef TEXT_WINDOW_H_INCLUDED
#define TEXT_WINDOW_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "font_cache.h"
#include "game_window.h"
#include "idle_processor.h"
#include "pixel_24.h"
#include "scrollbar_ptr.h"
#include "string_vector.h"
#include "text_justification.h"
#include "text_window_ptr.h"
#include "window_handler.h"

class   t_button;

// --------------------------------------------------------------
// text window class
// --------------------------------------------------------------
class t_text_window : public t_window
{
public:
	t_text_window( t_cached_font& font, t_screen_rect const& rect, t_window* parent = 0,
		           std::string const& text = "", t_pixel_24 const& color = t_pixel_24(0,0,255), 
				   bool disable_scrollbar = false, bool start_at_bottom = false);
	t_text_window( t_cached_font& font, t_screen_point point, t_window* parent = 0, 
		           std::string const& text = "", t_pixel_24 const& color = t_pixel_24(0,0,255));

	virtual void		 on_size_change( t_screen_rect const& rect );
	t_cached_font const& get_font() const;
	int                  get_line_count() const;
	int                  get_scroll_max_value() const;
	int	                 get_scroll_position() const;
	int                  get_scroll_step() const;
	bool				 get_start_at_bottom() const;
	std::string          get_text() const;
	int                  get_text_height() const;
	void				 set_center_horizontal( bool arg = true );
	void				 set_center_vertical( bool arg = true );
	void				 set_color( t_pixel_24 color );
	void				 set_drop_shadow( bool arg, t_pixel_24 const& color = t_pixel_24(0,0,0) );
	void				 set_font( t_cached_font& font );
	void                 set_justification( t_justification arg );
	void				 set_right_justified( bool arg = true );
	virtual void         set_scroll_position( int pos );
	void				 set_start_at_bottom( bool arg = true );
	void				 set_text( std::string const& text );
	void				 set_wrapped_text( t_string_vector const & wrapped_text, int text_width );

	virtual void paint( t_paint_surface& paint_surface );
protected:
	t_text_window( t_cached_font& font, t_window* parent = 0, char const* text = "", 
		           t_pixel_24 color = t_pixel_24(0,0,255));
    void            button_scroll_down_arrow( t_button * );
    void            button_scroll_up_arrow( t_button * );
	t_screen_point get_row_start( int row ) const;
	virtual void   on_text_change();
	void		    init_scrollbar();
	void            slider_change( t_scrollbar* scrollbar, int value );

	t_justification m_justification;

	bool			m_button_scroll_active;
    t_button*       m_button_down;
    t_button*       m_button_up;

	bool            m_center_vertical;
	bool			m_disable_scrollbar;
	bool            m_drop_shadow;
	t_cached_font   m_font;
	std::string     m_text;
	t_uint16        m_color;
	t_uint16        m_shadow_color;
	bool			m_start_at_bottom;
	t_string_vector m_text_block;
	int             m_text_width;

	t_scrollbar_ptr	m_scrollbar;
	bool			m_scrollbar_active;
	int				m_scroll_max_value;
	int				m_scroll_pixel_position;
	int				m_scroll_step;


	bool			m_bfirst;

};


inline t_cached_font const& t_text_window::get_font() const
{
	return m_font;
}

inline int t_text_window::get_scroll_max_value() const
{
	return m_scroll_max_value;
}

inline int t_text_window::get_scroll_position() const
{
	return m_scroll_pixel_position;
}

inline int t_text_window::get_scroll_step() const
{
	return m_scroll_step;
}

inline bool t_text_window::get_start_at_bottom() const
{
	return m_start_at_bottom;
}

inline std::string t_text_window::get_text() const
{
	return m_text;
}

inline void t_text_window::set_center_horizontal( bool arg )
{
	if (arg)
		m_justification = k_justify_center;
	else
		m_justification = k_justify_left;
}

inline void t_text_window::set_center_vertical( bool arg )
{
	m_center_vertical = arg;
}

inline void t_text_window::set_right_justified( bool arg )
{
	if (arg)
		m_justification = k_justify_right;
	else
		m_justification = k_justify_left;
}

inline void t_text_window::set_start_at_bottom( bool arg )
{
	m_start_at_bottom = arg;
}

inline void t_text_window::set_justification( t_justification arg )
{
	m_justification = arg;
}

inline int t_text_window::get_line_count() const
{
	return m_text_block.size();
}

inline void t_text_window::set_scroll_position( int pos )
{
	m_scroll_pixel_position = pos;
}


// --------------------------------------------------------------
// timed scrolling text window class
// --------------------------------------------------------------
class t_scrolling_text_window : public t_text_window, public t_idle_processor
{
public:
				t_scrolling_text_window( t_cached_font& font, t_screen_rect const& rect, t_window* parent = 0,
					   std::string const& text = "", t_pixel_24 const& color = t_pixel_24(0,0,255), int total_time = 10000 );

	int					get_delay() const;
	t_window_handler	get_end_handler() const;
	int					get_total_time() const;
	void				set_end_handler( t_window_handler handler );
	int					get_elapsed_time() const;
	void				set_elapsed_time( int time );

protected:
	void				on_idle();

	int					m_delay;
	int					m_total_time;
	t_window_handler	m_end_handler;
	int					m_elapsed_time;
private:
	int					m_delay_per_pixel;
	int					m_pixel_time_elapsed;
};

// --------------------------------------------------------------
// timed scrolling text window class
// --------------------------------------------------------------
inline int t_scrolling_text_window::get_delay() const
{
	return m_delay;
}

// --------------------------------------------------------------
// --------------------------------------------------------------
inline t_window_handler t_scrolling_text_window::get_end_handler() const
{
	return m_end_handler;
}

// --------------------------------------------------------------
// timed scrolling text window class
// --------------------------------------------------------------
inline int t_scrolling_text_window::get_total_time() const
{
	return m_total_time;
}

// --------------------------------------------------------------
// timed scrolling text window class
// --------------------------------------------------------------
inline int t_scrolling_text_window::get_elapsed_time() const
{
	return m_elapsed_time;
}

inline void t_scrolling_text_window::set_end_handler( t_window_handler handler )
{
	m_end_handler = handler;
}

inline void t_scrolling_text_window::set_elapsed_time( int time )
{
	m_elapsed_time = time;
}




#endif // TEXT_WINDOW_H_INCLUDED
